<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .div1 {
      width: 300px;
      height: 300px;
      background-color: black;
      margin-top: 10px
    }
    .div2 {
      width: 200px;
      height: 200px;
      background-color: darkcyan;
      margin-top: 10px
    }
  </style>
</head>
<body>
<div>
  <div class="div1">
  </div>
  <div class="div2" >div2</div>
</div>
</body>
<script type='text/javascript'>
  function fun(name) {
    return function() {
      console.log('我的名字是', name)
    }
  }
  const div1 = document.getElementsByClassName('div1')[0]
  const div2 = document.getElementsByClassName('div2')[0]
  const name1 = fun('我是div1')
  const name2 = fun('我是div2')
  div1.onclick = name1
  div2.onclick = name2
</script>
</html>
